﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using CardInChina.Bussiness.Frontend.Models;

namespace CardInChina.Web.Mvc
{
    public class CICBasicController : Controller
    {
        private User user = new User();

        public User CurrentUser
        {
            get { return user; }
        }

        public CustomerInfo CustomerInfo
        {
            get { return user.Details; }
        }

        protected override void Execute(System.Web.Routing.RequestContext context)
        {
            // Set outside referer for register
            CurrentUser.TrySaveReferrer(context.HttpContext.Request);
        
            base.Execute(context);
        }

#if !DEBUG
        protected override void OnException(ExceptionContext context)
        {
            // Bail if we can't do anything; app will crash.
            if (context == null)
                return;

            // TODO: Log


            // 以下代码不需要，当Web.config里面customErrors启用时，页面一定会加载Error.cshtml
            //context.ExceptionHandled = true;
            //var data = new HandleErrorInfo(context.Exception, "Unknown Controller", "Unknown Action");
            //context.HttpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
            //context.Result = View("Error", data);
        }
#endif

    }
}